﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Configuration;
using 通用类库.Utils;
using System.IO;
using System.Collections.Concurrent;

namespace 通用类库.DataProvider
{
    public delegate void OnStockPriceChangeDelegate(Object sender, StockPriceChangeEventArgs e);

    public class StockDataTDX : MarshalByRefObject
    {
        private static readonly log4net.ILog loghelper = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public event OnStockPriceChangeDelegate OnStockPriceChanged; //当stock价格数据改变的时候通知 
        private ConcurrentDictionary<string, Thread> stockThread = new ConcurrentDictionary<string, Thread>();

        public override object InitializeLifetimeService()
        {
            return null;
        }
        private Dictionary<string, Thread> stockPriceThread = null;

        bool? _saveDataFiles = null;
        bool SaveDataFiles
        {
            get
            {
                if (!_saveDataFiles.HasValue)
                {
                    if (ConfigurationManager.AppSettings["TDXDataSaveDataFiles"] != null)
                        _saveDataFiles = bool.Parse(ConfigurationManager.AppSettings["TDXDataSaveDataFiles"]);
                    else
                        _saveDataFiles = false;
                }
                return _saveDataFiles.Value;
            }
        }
        string ServerIP
        {
            get
            {
                if (ConfigurationManager.AppSettings["TDXDataServerIP"] != null)  //通过前端获取数据存储方IP
                    return ConfigurationManager.AppSettings["TDXDataServerIP"];
                return "119.147.212.81"; //否则返回平常存储数据IP 
            }
        }
        Int32 ServerPort
        {
            get
            {
                if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["TDXDataServerPort"]))
                    return Int32.Parse(ConfigurationManager.AppSettings["TDXDataServerPort"]);
                return 7709;
            }
        }
        internal StockDataTDX()
        {
            log4net.Config.XmlConfigurator.Configure();
        }


        public bool Logout()
        {
            TradeDataTDX.TdxHq_Disconnect();
            return true;
        }

        public bool Start()
        {
            StartListen();
            stockPriceThread = new Dictionary<string, Thread>();

            return true;
        }

        private void StartListen()
        {
            StringBuilder Result = new StringBuilder(1024 * 1024);
            StringBuilder ErrInfo = new StringBuilder(256);
            bool iReturn = TradeDataTDX.TdxHq_Connect(ServerIP, ServerPort, Result, ErrInfo);
        }

        private void OnStockPriceChangedHandler(object obj)  //????
        {
            StockLevel2Info data = obj as StockLevel2Info;
            OnStockPriceChanged?.Invoke(this, new StockPriceChangeEventArgs(data));
        }
        private static object synchCall = new object();
        private void innerGetStockDataFromProvider(string stockCode, byte market, ref StringBuilder sLevel2Result, ref StringBuilder sDetailOrderResult, ref StringBuilder sDetailTransactionResult, ref StringBuilder sSailBuyResult)
        {
            StringBuilder sErrInfo = new StringBuilder(256);
            byte[] marketList = new byte[] { market };
            string[] zqdm = new string[] { stockCode };
            short count = 1;

            //lock (synchCall)
            {
                #region (TdxHq_GetSecurityQuotes)获取五档报价
                /**
                 * 市场：0
                 * 代码：1
                 * 活跃度：2
                 * 现价：3
                 * 昨收：4
                 * 开盘：5
                 * 最高：6
                 * 最低：7
                 * 时间：8
                 * 保留：9
                 * 总量：10
                 * 现量：11
                 * 总金额：12
                 * 内盘：13
                 * 外盘：14
                 * 保留：15
                 * 保留：16
                 * 买一价：17
                 * 卖一价：18
                 * 买一量：19
                 * 卖一量：20
                 * 买二价：21
                 * 卖二价：22
                 * 买二量：23
                 * 卖二量：24
                 * 买三价：25
                 * 卖三价	：26
                 * 买三量	：27
                 * 卖三量	：28
                 * 买四价	：29
                 * 卖四价：30
                 * 买四量：31
                 * 卖四量：32
                 * 买五价：33
                 * 卖五价	：34
                 * 买五量	：35
                 * 卖五量	：36 
                 * 
                 * 保留 ：37
                 * 保留 ：38
                 * 保留 ：39
                 * 保留 ：40
                 * 保留 ：41
                 * 涨速 ：42
                 * 活跃度 ：43
                 */
                TradeDataTDX.TdxHq_GetSecurityQuotes(marketList, zqdm, ref count, sLevel2Result, sErrInfo);//批量获取多个证券的十档报价数据 
                if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                {
                    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                    StartListen();
                    TradeDataTDX.TdxHq_GetSecurityQuotes(marketList, zqdm, ref count, sLevel2Result, sErrInfo);
                }
                #endregion

                #region (TdxHq_GetHistoryTransactionData)获取历史分时成交数据
                /**
                 * 时间	：0
                 * 价格 ：1
                 * 现量 ：2
                 * 买卖 ：3
                 * 保留 ：4
                 */
                //count = 2000;
                //StockDataTradeX.TdxHq_GetHistoryTransactionData(market, stockCode, 0, ref count, 20180103, sDetailTransactionResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetHistoryTransactionData(market, stockCode, 0, ref count, 20180104, sDetailTransactionResult, sErrInfo);
                //}
                #endregion

                #region (TdxHq_GetTransactionData)获取分时成交数据
                /**
                 * 
                 * 时间 ：0
                 * 价格 ：1
                 * 现量 ：2
                 * 笔数 ：3
                 * 买卖 ：4
                 * 保留 ：5
                 * 
                 */
                //count = 2000;
                //StockDataTradeX.TdxHq_GetTransactionData(market, stockCode, 0, ref count, sDetailTransactionResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetTransactionData(market, stockCode, 0, ref count, sDetailTransactionResult, sErrInfo);
                //}
                #endregion

                #region (TdxHq_GetSecurityCount)获取市场内所有证券的数量

                ////获取市场内所有证券的数量

                ////证券数量
                //short result = 0;

                //StockDataTradeX.TdxHq_GetSecurityCount(market,ref result, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetSecurityCount(market, ref result, sErrInfo);
                //}
                #endregion

                #region (TdxHq_GetSecurityList)获取市场内从某个位置开始的1000支股票的股票代码
                /**
                 * 代码:0
                 * 一手股数:1
                 * 名称:2
                 * 保留:3
                 * 保留:4
                 * 昨收:5
                 * 保留:6
                 * 保留:7
                 */
                ////获取市场内从某个位置开始的1000支股票的股票代码
                //short start = 0;
                //short StockCount = 0;
                //StockDataTradeX.TdxHq_GetSecurityList(market, start,ref  StockCount, sResult,sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetSecurityList(market, start,ref  StockCount, sResult,sErrInfo);
                //}
                #endregion

                #region(TdxHq_GetSecurityBars)获取证券的K线数据
                /**
                 * 时间:0	
                 * 开盘价:1	
                 * 收盘价:2
                 * 最高价:3
                 * 最低价:4
                 * 成交量:5
                 * 成交额:6
                 */

                //K线种类, 
                //0->5分钟K线 //1->15分钟K线 //2->30分钟K线  
                //3->1小时K线  //4->日K线   //5->周K线  
                //6->月K线   //7->1分钟    //10->季K线  //11->年K线
                //byte Category = 0;
                //证券代码
                //string Zqdm = stockCode;
                //short start = 1;
                //short StockCount = 100;
                ////获取证券的K线数据
                //StockDataTradeX.TdxHq_GetSecurityBars(Category,market, Zqdm, start, ref StockCount,sResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetSecurityBars(Category, market, Zqdm, start, ref StockCount, sResult, sErrInfo);
                //}
                #endregion

                #region (TdxHq_GetIndexBars)获取指数的K线数据

                /**
                 * 时间	:0
                 * 开盘价:1	
                 * 收盘价:2
                 * 最高价:3
                 * 最低价:4
                 * 成交量:5
                 * 成交额:6	
                 * 涨家数:7	
                 * 跌家数:8
                 */
                //
                //StockDataTradeX.TdxHq_GetIndexBars(Category, market, Zqdm, start, ref StockCount, sResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetIndexBars(Category, market, Zqdm, start, ref StockCount, sResult, sErrInfo);
                //}

                #endregion

                #region (TdxHq_GetMinuteTimeData)获取分时数据

                /**
                 * 时间：0	
                 * 开盘价：1	
                 * 收盘价：2
                 * 最高价：3
                 * 最低价：4
                 * 成交量：5
                 * 成交额：6
                 * 涨家数：7
                 * 跌家数：8
                 */
                //获取分时数据
                //StockDataTradeX.TdxHq_GetMinuteTimeData(market, stockCode,  sResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetMinuteTimeData(market, stockCode, sResult, sErrInfo);
                //}
                #endregion

                #region (TdxHq_GetHistoryMinuteTimeData)获取历史分时数据   （没有数据）
                //int Date = 20140101;
                ////获取历史分时数据
                ////没有数据？
                //StockDataTradeX.TdxHq_GetHistoryMinuteTimeData(market, stockCode, Date, sResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetHistoryMinuteTimeData(market, stockCode, Date, sResult, sErrInfo);
                //}
                #endregion

                #region (TdxHq_GetCompanyInfoCategory)获取F10资料的分类
                /**
                 * 文件:0 
                 * 开始:1
                 * 长度:2
                 * 最新提示:3
                 */

                //获取F10资料的分类
                //StockDataTradeX.TdxHq_GetCompanyInfoCategory(market, stockCode, sResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetCompanyInfoCategory(market, stockCode,  sResult, sErrInfo);
                //}
                #endregion

                #region (TdxHq_GetCompanyInfoContent)获取F10资料的某一分类的内容
                /**
                 * 返回字符串
                 */
                //string FileName = "601857.txt";
                //int Start = 0;
                //int Length = 10008;
                ////获取F10资料的某一分类的内容
                //StockDataTradeX.TdxHq_GetCompanyInfoContent(market, stockCode, FileName,Start,Length,sResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetCompanyInfoContent(market, stockCode, FileName, Start, Length, sResult, sErrInfo);
                //}
                #endregion

                #region (TdxHq_GetXDXRInfo)获取除权除息信息
                /**
                 * 市场:0
                 * 证券代码:1 
                 * 日期:2  
                 * 保留:3
                 * 送现金:4                
                 * 配股价:5
                 * 送股数:6        
                 * 配股比例:7 
                 */
                //StockDataTradeX.TdxHq_GetXDXRInfo(market, stockCode, sResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetXDXRInfo(market, stockCode, sResult, sErrInfo);
                //}
                #endregion

                #region (TdxHq_GetFinanceInfo)获取财务信息
                /**
                 * 市场 :0	
                 * 证券代码 :1
                 * 流通股本 :2
                 * 所属省份 :3
                 * 所属行业 :4
                 * 财务更新日期 :5
                 * 上市日期	 :6
                 * 总股本 :7
                 * 国家股 :8
                 * 发起人法人股:9
                 * 法人股 :10
                 * B股 :11
                 * H股 :12
                 * 职工股 :13
                 * 总资产 :14
                 * 流动资产 :15
                 * 固定资产 :16
                 * 无形资产 :17
                 * 股东人数 :18
                 * 流动负债 :19
                 * 长期负债 :20
                 * 资本公积金 :21
                 * 净资产 :22
                 * 主营收入 :23
                 * 主营利润 :24
                 * 应收帐款 :25
                 * 营业利润 :26
                 * 投资收益 :27
                 * 经营现金流 :28
                 * 总现金流 :29	
                 * 存货 :30
                 * 利润总额 :31
                 * 税后利润 :32	
                 * 净利润 :33
                 * 未分利润 :34	
                 * 保留 :35
                 * 保留1 :36
                 */

                //StockDataTradeX.TdxHq_GetFinanceInfo(market, stockCode, sResult, sErrInfo);
                //if (!string.IsNullOrEmpty(sErrInfo.ToString()))
                //{
                //    loghelper.Error("innerGetStockDataFromProvider  Exception:" + sErrInfo.ToString());
                //    StartListen();
                //    StockDataTradeX.TdxHq_GetFinanceInfo(market, stockCode, sResult, sErrInfo);
                //}
                #endregion

                if (SaveDataFiles)
                    loghelper.DebugFormat("{0}____{1}____{2}____{3}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), stockCode, sLevel2Result.ToString(), sDetailTransactionResult.ToString());


            }
        }

        private static object synchObj = new object();
        public bool SubscribeStock(string stockCode)
        {
            lock (synchObj)
            {  
                loghelper.Info("SubscribeStock " + stockCode);  
                if (!stockThread.ContainsKey(stockCode))
                { 
                    Thread threadDeal = new Thread(new ParameterizedThreadStart(DealThread));
                    threadDeal.Start(stockCode);
                    stockThread[stockCode] = threadDeal;
                }
            }
            return true;
        }
        private void DealThread(object obj)
        {
            string strStockCode = obj as string; 
            DateTime dtWriteLog = DateTime.Now; 
            while (true)
            {
                if (DateTime.Now.Hour < 9 ||
                    (DateTime.Now.Hour == 9 && DateTime.Now.Minute < 15) ||
                    DateTime.Now.Hour > 15 ||
                    (DateTime.Now.Hour == 15 && DateTime.Now.Minute > 15) ||
                    DateTime.Now.DayOfWeek == DayOfWeek.Sunday ||
                    DateTime.Now.DayOfWeek == DayOfWeek.Saturday
                    )
                {
                    Thread.Sleep(1000);
                    continue;
                }
                try
                {
                    lock (synchCall)
                    {
                        StockLevel2Info priceInfo = GetStockPrice(strStockCode);
                        OnStockPriceChangedHandler(priceInfo);
                    }
                }
                catch (Exception ex)
                {
                    loghelper.Error("Stock data  DealThread Exception:", ex);
                    Thread.Sleep(100);
                }
                Thread.Sleep(1000);
            }
        }
        public StockLevel2Info GetStockPrice(string stockCode)
        {
            StockLevel2Info priceInfo = new StockLevel2Info();
            priceInfo.StockCode = stockCode;
            StringBuilder sLevel2Result = new StringBuilder(1024 * 1024);
            StringBuilder sDetailTransactionResult = new StringBuilder(1024 * 1024);
            StringBuilder sDetailOrderResult = new StringBuilder(1024 * 1024);
            StringBuilder sSailBuyResult = new StringBuilder(1024 * 1024);

            byte market = 0;
            if (Int32.Parse(priceInfo.StockCode) >= 500000)
                market = 1;
            if (true)
            {
                DateTime dtBegin = DateTime.Now;
                try
                {
                    sLevel2Result.Clear();
                    sDetailTransactionResult.Clear();
                    sDetailOrderResult.Clear();
                    innerGetStockDataFromProvider(priceInfo.StockCode, market, ref sLevel2Result, ref sDetailOrderResult, ref sDetailTransactionResult, ref sSailBuyResult);
                    loghelper.InfoFormat("getta cost:{0}ms--->{1}-{2}", (DateTime.Now - dtBegin).TotalMilliseconds.ToString("##.00"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"), priceInfo.StockCode);
                    //分析数据并缓存起来
                    GetLevel2Info(sLevel2Result, ref priceInfo);
                    //GetDetailTransaction(sDetailTransactionResult, ref priceInfo);
                    //GetDetailOrder(sDetailOrderResult, ref priceInfo);
                    loghelper.InfoFormat("total cost:{0}ms", (DateTime.Now - dtBegin).TotalMilliseconds.ToString("##.00"));
                    if (SaveDataFiles)
                    {
                        string fileContent = StringUtil.Serializer<StockLevel2Info>(priceInfo);
                        string strPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data\\" + DateTime.Now.ToString("yyyyMMdd"));
                        if (!Directory.Exists(strPath))
                            Directory.CreateDirectory(strPath);
                        string strFileName = Path.Combine(strPath, priceInfo.StockCode + ".dat");
                        File.AppendAllText(strFileName, fileContent + Environment.NewLine);
                    }
                }
                catch (Exception ex)
                {
                    loghelper.Error("ThreadStockPriceChange  Exception:", ex);
                }
                finally
                {
                }
            }
            return priceInfo;
        }

        internal List<StockLevel2Info> GetAllMarketStock()
        {
            short start = 0;
            short StockCount = 0;
            StringBuilder Result = new StringBuilder(1024 * 1024);
            StringBuilder ErrInfo = new StringBuilder(256);
            List<StockLevel2Info> returnValue = new List<DataProvider.StockLevel2Info>();
            //获取深市的股票
            for (byte market = 0; market < 2;)
            {
                TradeDataTDX.TdxHq_GetSecurityList(market, start, ref StockCount, Result, ErrInfo);
                if (StockCount == 0)
                    market++;
                string[] strRows = Result.ToString().Split(new char[] { '\n' });
                string strReturn = string.Empty;
                for (int i = 1; i < strRows.Length; i++)
                {
                    string[] strArray = strRows[i].Split(new char[] { '\t' });

                    if (strArray.Length > 4)
                    {
                        StockLevel2Info tmpInfo = new StockLevel2Info();
                        tmpInfo.StockName = strArray[2];
                        tmpInfo.StockCode = strArray[0];
                        returnValue.Add(tmpInfo);
                    }
                }
                start += StockCount;
            }
            return returnValue;
        }

        /**
         * 市场：0
         * 代码：1
         * 活跃度：2
         * 现价：3
         * 昨收：4
         * 开盘：5
         * 最高：6
         * 最低：7
         * 时间：8
         * 保留：9
         * 总量：10
         * 现量：11
         * 总金额：12
         * 内盘：13
         * 外盘：14
         * 保留：15
         * 保留：16
         * 买一价：17
         * 卖一价：18
         * 买一量：19
         * 卖一量：20
         * 买二价：21
         * 卖二价：22
         * 买二量：23
         * 卖二量：24
         * 买三价：25
         * 卖三价 ：26
         * 买三量 ：27
         * 卖三量 ：28
         * 买四价 ：29
         * 卖四价：30
         * 买四量：31
         * 卖四量：32
         * 买五价：33
         * 卖五价 ：34
         * 买五量 ：35
         * 卖五量 ：36 
         * 保留 ：37
         * 保留 ：38
         * 保留 ：39
         * 保留 ：40
         * 保留 ：41
         * 涨速 ：42
         * 活跃度 ：43
         **/

        private void GetLevel2Info(StringBuilder sLevel2Result, ref StockLevel2Info priceInfo)
        {
            string[] strRows = sLevel2Result.ToString().Split(new char[] { '\n' });
            for (int i = 1; i < strRows.Length; i++)
            {
                string[] strArray = strRows[i].Split(new char[] { '\t' });
                if (strArray.Length > 10)
                {
                    priceInfo.OpenPrice = StringUtil.getDecimal(strArray[5]);//开盘
                    priceInfo.PreClosePrice = StringUtil.getDecimal(strArray[4]);//昨日收盘
                    priceInfo.Price = StringUtil.getDecimal(strArray[3]);//当前价格
                    priceInfo.HighPrice = StringUtil.getDecimal(strArray[6]);//最高
                    priceInfo.LowPrice = StringUtil.getDecimal(strArray[7]);//最低

                    priceInfo.MatchNumber = (Int32)((double)StringUtil.getDecimal(strArray[2]));//活跃度
                    priceInfo.MatchAmount = (Int32)((double)StringUtil.getDecimal(strArray[11]));//现量

                    priceInfo.TotalAmount = (Int32)((double)StringUtil.getDecimal(strArray[10]));//总量
                    priceInfo.TotalVolume = (Int32)((double)StringUtil.getDecimal(strArray[12]));//总金额

                    priceInfo.Buy1Price = StringUtil.getDecimal(strArray[17]);
                    priceInfo.Sale1Price = StringUtil.getDecimal(strArray[18]);
                    priceInfo.Buy1Amount = (Int32)((double)StringUtil.getDecimal(strArray[19]));
                    priceInfo.Sale1Amount = (Int32)((double)StringUtil.getDecimal(strArray[20]));

                    priceInfo.Buy2Price = StringUtil.getDecimal(strArray[21]);
                    priceInfo.Sale2Price = StringUtil.getDecimal(strArray[22]);
                    priceInfo.Buy2Amount = (Int32)((double)StringUtil.getDecimal(strArray[23]));
                    priceInfo.Sale2Amount = (Int32)((double)StringUtil.getDecimal(strArray[24]));


                    priceInfo.Buy3Price = StringUtil.getDecimal(strArray[25]);
                    priceInfo.Sale3Price = StringUtil.getDecimal(strArray[26]);
                    priceInfo.Buy3Amount = (Int32)((double)StringUtil.getDecimal(strArray[27]));
                    priceInfo.Sale3Amount = (Int32)((double)StringUtil.getDecimal(strArray[28]));


                    priceInfo.Buy4Price = StringUtil.getDecimal(strArray[29]);
                    priceInfo.Sale4Price = StringUtil.getDecimal(strArray[30]);
                    priceInfo.Buy4Amount = (Int32)((double)StringUtil.getDecimal(strArray[31]));
                    priceInfo.Sale4Amount = (Int32)((double)StringUtil.getDecimal(strArray[32]));


                    priceInfo.Buy5Price = StringUtil.getDecimal(strArray[33]);
                    priceInfo.Sale5Price = StringUtil.getDecimal(strArray[34]);
                    priceInfo.Buy5Amount = (Int32)((double)StringUtil.getDecimal(strArray[35]));
                    priceInfo.Sale5Amount = (Int32)((double)StringUtil.getDecimal(strArray[36]));

                    priceInfo.PriceDataTime = DateTime.Now;

                    if (priceInfo.Price <= 0)
                    {
                        priceInfo.Price = priceInfo.PreClosePrice;
                        priceInfo.Buy1Price = priceInfo.PreClosePrice;
                        priceInfo.Sale1Price = priceInfo.PreClosePrice;

                        priceInfo.Buy2Price = priceInfo.PreClosePrice;
                        priceInfo.Sale2Price = priceInfo.PreClosePrice;

                        priceInfo.Buy3Price = priceInfo.PreClosePrice;
                        priceInfo.Sale3Price = priceInfo.PreClosePrice;

                        priceInfo.Buy4Price = priceInfo.PreClosePrice;
                        priceInfo.Sale4Price = priceInfo.PreClosePrice;

                        priceInfo.Buy5Price = priceInfo.PreClosePrice;
                        priceInfo.Sale5Price = priceInfo.PreClosePrice;
                    }
                }
            }
        }

    }
}
